import { eventtarget } from "./eventtarget";
import { anchorscroll } from "./anchorscroll";
import { loaddone } from "./loaddone";
import { routerpagegethandler } from "./routerpageget";
import { 窄屏隐藏侧边栏 } from "./窄屏隐藏侧边栏";
import { sidebarscroll } from "./sidebarscroll";

eventtarget.addEventListener("load", loaddone);
eventtarget.addEventListener("load", anchorscroll);
eventtarget.addEventListener("load", sidebarscroll);

eventtarget.addEventListener(
    "mount",
    () => {
        let eventname: string;
        if (process.env.PRERENDER) {
            eventname = "popstate";
        } else {
            eventname = "hashchange";
        }
        window.addEventListener(eventname, routerpagegethandler);
    },
    { once: true }
);
eventtarget.addEventListener(
    "mount",
    () => {
        窄屏隐藏侧边栏();
    },
    { once: true }
);
eventtarget.addEventListener("load", () => {
    窄屏隐藏侧边栏();
});
if (process.env.PRERENDER) {
    eventtarget.addEventListener("load", () => {
        requestAnimationFrame(() => {
            //@ts-ignore
            requestIdleCallback(() => {
                document.dispatchEvent(new Event("__RENDERED__"));
            });
        });
    });
}
